R Data input and output

input and output data to csv;excel ect

R
Author

Tony Duan

Published

July 5, 2023

Code
library(tidyverse)
library(openxlsx)
library(readxl)

1 CSV

1.1 input with read_csv()

Code
data001=read_csv('data001 csv data.csv')
head(data001)

1.2 output with write.csv

Code
write.csv(data001,'data001 csv output data.csv')

2 EXCEl

2.1 input with read_excel()

Code
data001=read_excel('data001 excel data.xlsx')
head(data001)

2.2 output with write.xlsx

Code
write.xlsx(data001,'data001 excel output data.xlsx')

3 Read from googlesheet

Code
library(googlesheets4)

excel file link:

Code
link='https://docs.google.com/spreadsheets/d/14_suWY8fCPEXV0MH7ZQMZ-KndzMVsSsA5HdR-7WqAC0'

find sheet names

Code
sheet_names(link)

3.1 read excel by sheet names with read_sheet()

Code
aa=read_sheet(link,"data-for-countries-etc-by-year")
Code
head(aa)

4 using pins pacakge

5 Reference